package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description: TODO
 * @Author: Mr.Cao
 * @DateTime: 2021/9/28 19:06
 * BMW F750GS
 **/
@Api(tags = "商品后台")//swagger注解
@RestController
@RequestMapping("admin/product")
//@CrossOrigin //解决跨域问题, 已配置网关,不需要该注解
public class BaseManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 获取一级分类
     * */
    @GetMapping("getCategory1")
    @ApiOperation(value = "获取一级分类")
    public Result getCategory1(){
        return Result.ok(manageService.getCategory1());
    }
    /**
     * 获取二级分类
     * */
    @GetMapping("getCategory2/{category1Id}")
    @ApiOperation(value = "获取二级分类")
    public Result getCategory2(
            @PathVariable long category1Id
    ){
        return Result.ok(manageService.getCategory2(category1Id));
    }

    /**
     * 获取三级分类
     * */
    @GetMapping("getCategory3/{category2Id}")
    @ApiOperation(value = "获取三级分类")
    public Result getCategory3(
            @PathVariable long category2Id
    ){
        return Result.ok(manageService.getCategory3(category2Id));
    }
    /**
     * 根据分类id获取平台属性
     */
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(
            @PathVariable long category1Id,
            @PathVariable long category2Id,
            @PathVariable long category3Id
    ){

        return Result.ok(manageService.attrInfoList(category1Id,category2Id,category3Id));
    }

    /**
     * 添加平台属性
     * */
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    /**
     * 根据平台属性ID获取平台属性
     * */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable long attrId){
       return Result.ok(manageService.getAttrValueList(attrId));
    }
    /**
     * 分页获取品牌列表
     * */
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable long page,@PathVariable long limit){
        IPage<BaseTrademark> pageList =   manageService.baseTrademark(page,limit);
    return Result.ok(pageList);
    }

    /**
     * 保存品牌列表
     * */
    @PostMapping("baseTrademark/save")
    public Result baseTrademarkSave(@RequestBody BaseTrademark baseTrademark){
        manageService.baseTrademarkSave(baseTrademark);
        return Result.ok();
    }
    /**
     * 编辑品牌列表,数据回显,根据id查询品牌信息
     * */
    @GetMapping("baseTrademark/get/{id}")
    public Result getBaseTrademarkById(@PathVariable long id){
          BaseTrademark baseTrademark =   manageService.getBaseTrademarkById(id);
        return Result.ok(baseTrademark);
    }

    /**
     * 根据id 删除品牌列表
     * */
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result removeBaseTrademarkById(@PathVariable long id){
       manageService.removeBaseTrademarkById(id);
        return Result.ok();
    }

    /**
     * 根据id 更新品牌信息
     * */
    @PutMapping("baseTrademark/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        manageService.updateBaseTrademark(baseTrademark);
        return Result.ok();
    }

}
